/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.belfalas.simy86;

import org.belfalas.simy86.operadores.*;

/**
 *
 * @author belfalas
 */
public class OperadorFactory {

    public static Operador getOperador(short code) {
        byte icode = (byte) (code >> 4);
        byte ifun = (byte) (code & 0xF);

        switch (icode) {
            case 0x0: {
                return new NOP();
            }
            case 0x1: {
                return new HALT();
            }
            case 0x2: {
                return new RRMOVL();
            }
            case 0x3: {
                return new IRMOVL();
            }
            case 0x4: {
                return new RMMOVL();
            }
            case 0x5: {
                return new MRMOVL();
            }
            case 0x6: {
                switch (ifun) {
                    case 0x0: {
                        return new ADDL();
                    }
                    case 0x1: {
                        return new SUBL();
                    }
                    case 0x2: {
                        return new ANDL();
                    }
                    case 0x3: {
                        return new XORL();
                    }
                    case 0x4: {
                        return new INCL();
                    }
                    case 0x5: {
                        return new DECL();
                    }
                    case 0x6: {
                        return new NOTL();
                    }
                    case 0x7: {
                        return new ORL();
                    } 
                    case 0x8: {
                        return new SHLL();
                    } 
                    case 0x9: {
                        return new SHRL();
                    }                    
                }
            }
            case 0x7: {
                switch (ifun) {
                    case 0x0: {
                        return new JMP();
                    }
                    case 0x1: {
                        return new JLE();
                    }
                    case 0x2: {
                        return new JL();
                    }
                    case 0x3: {
                        return new JE();
                    }
                    case 0x4: {
                        return new JNE();
                    }
                    case 0x5: {
                        return new JGE();
                    }
                    case 0x6: {
                        return new JG();
                    }                 
                }
            }
            case 0x8: {
                return new CALL();
            }
            case 0x9: {
                return new RET();
            }
            case 0xA: {
                return new PUSHL();
            }
            case 0xB: {
                return new POPL();
            }
        }
        return null;
    }
}
